﻿using Dapper.MsSql.Library;
using Sql.DataBase;
using System;
using System.Linq;
using static Common.Library.EnumExtentions;

namespace Dapper.MsSql.Test
{
    class Program
    {
        static void Main(string[] args)
        {

            var user = new SysUserEntity
            {
                gCode = Guid.NewGuid().ToString("N"),
                sLoginName = "admin1",
                sPassword = "4297F44B13955235245B2497399D7A93",
                sUserName = "123",
                iState = 1,
                dCreateTime = DateTime.Now,
                sPhone = "15824575865",
                iSex = 1,
                bIsDeleted = false
            };
            //using (var con = DataBase.GetConnection(DatabaseName.GeneralFrameworkDB.GetEnumItemDescription()))
            //{
            //    var insertResult = con.CommandSet<SysUserEntity>().Insert(user);
            //    Console.WriteLine("Insert添加数{0}", insertResult);
            //}

            using (var con = MsSqlDataBase.GetConnection(DatabaseName.AuthorityDB_MsSql))
            {
                var result = con.QuerySet<SysUserEntity>()
                    .AndWhere(p => p.iSex == 1 && p.sPhone.StartsWith(user.iSex.ToString())).Multiple()
                    .ToList<SysUserEntity>();

                //Console.WriteLine("Multiple查询信息{0}", result.ObjectToJSON());
            }


            using (var con = MsSqlDataBase.GetConnection(DatabaseName.AuthorityDB_MsSql))
            {
                //var result = con.QuerySql<SysUserEntity>()
                //    .BySql("select * from SysUser where sUserName=@sUserName and iState=@iState", new { sUserName = "超级管理员",iState=1 })
                //    .Multiple()
                //    .ToList<SysUserEntity>();

                //var result1 = con.QuerySql<SysUserEntity>()
                //    .BySql("SELECT * FROM SysUser WHERE iState=@iState",user)
                //    .OrderBy(OrderByType.Asc,"iState")
                //    .Multiple()
                //    .ToList<SysUserEntity>();

                //var Result3 = con.QuerySet<SysUserEntity>().WithNoLock()
                //    .AndWhere(a => a.iState == 0)
                //    .OrderBy(OrderByType.Asc, "iState")
                //    .Select(a => a.sLoginName)
                //    .PageList(1, 2);

                //var result2 = con.QuerySql<SysUserEntity>()
                //   .BySql("SELECT * FROM SysUser WHERE iState=@iState", user)
                //   .OrderBy(OrderByType.Asc, "iState")
                //   .PageList(1, 10);

                //var result3 = con.QuerySql<SysUserEntity>()
                //   .BySql("SELECT * FROM SysUser WHERE iState=@iState", user)
                //   .Count();

                var result4 = con.QuerySql<SysUserEntity>()
                     .BySql("SELECT * FROM SysUser WHERE iState=@iState", new { iState= user.iState })
                     .Exists();

                //var Result6 = con.QuerySet<SysUserEntity>().WithNoLock()
                //    .AndWhere(a => a.iState == 0)
                //    .Sum(a => a.iState);

                var result5 = con.QuerySql<SysUserEntity>()
                  .BySql("SELECT * FROM SysUser WHERE iState=@iState", user)
                  .Sum(a => a.iState);

                Console.WriteLine("Multiple查询信息{0}", result5);
            }

            Console.ReadLine();
        }
    }
}
